Working set adjustment in a managed environment

ABSTRACT

An illustrative embodiment of a computer-implemented method for working set adjustment receives a request to use less heap memory than an original maximum forming a new maximum, and determines whether a garbage collection will move objects in response to the request. Responsive to a determination the garbage collection will move objects, add a first callback triggered by initiation of the garbage collection and invoking a handler for the first callback notifying a memory manager to free objects allocated by balloon. The first callback completes and the garbage collection starts. A handler for a second callback is invoked which notifies the memory manager to allocate balloon objects and frees backing memory to an operating system. Completion of the second call back allows the garbage collection to proceed as usual.

BACKGROUND

The present invention generally relates to managed environments in adata processing system and more specifically to optimization of workingset adjustment in a managed environment of a virtual machine of the dataprocessing system.

Heavily virtualized computing environments, for example, cloudcomputing, are designed to realize cost savings by maximizing density ofapplications enabled to run per unit of hardware. Maximizing density ofapplications improves utilization rates of the hardware and energyefficiency accordingly by eliminating idle machines.

In view of a significant portion of typical workloads being writtenusing the Java® programming language specification the managedenvironment of a Java virtual machine (JVM) should recognize and exploitthese virtualized environments. Java and all Java-based trademarks andlogos are trademarks of Oracle Corporation, and/or its affiliates, inthe United States, other countries or both. Maximization of applicationdensity typically requires the JVM to reduce a respective resourcefootprint, adapt to changing resource allocation, share more across JVMinstances, and leverage hypervisor-specific functionality including fastguest-to-guest network fabric.

Java Virtual Machines have traditionally operated in what may bedescribed as a “greedy” manner. The JVM often reserves resources up to amaximum allowed, even when the JVM does not necessarily need to do so.Further, once the JVM has used a resource, the resource is typicallyheld assuming a subsequent later use. While this behavior is optimalwhile resources are fully available as is common in conventionalenvironments, the practice however is not helpful with virtualizedenvironments where over-provisioning is commonly used based on knowledgenot all guests need maximum resource allocation concurrently.

An example of the current described behavior is a use of heap memory(memory used to store objects). Heap memory often grows, even whenunused space exists on the heap, and then only slowly returns memory tothe operating system, if at all. Over a period of time operating systemmemory allocated for an object heap in the JVM accordingly tends towardsa maximum, as allowed when the JVM was started, although the JVM mayonly need the maximum for previously defined intervals (for example,between 9-10 users traditionally log into a particular application).Because returning memory to the operating system (for example whenscanning, compacting) incurs a computational cost the JVM typicallyprefers to ‘hold’ extra memory rather than incurring a cleanup cost.Therefore, common practice advises customers never to simply avoidmemory over-provisioning for Java applications, which accordinglyreduces the value of virtualization.

Although there are few features to adjust heap sizes automatically usinghints from hypervisors, memory pressure or other dynamic attributes incurrent commercial JVM implementations, published articles disclosethese kinds of techniques. Techniques typically use a form of “balloon”to steal memory from a heap and return the memory to an operating system(or hypervisor) or adjust a maximum memory used by a collector to avalue set using external factors. Each of the techniques has advantagesand disadvantages described using a notation of Dn.

In one example using a balloon object, a required interaction with a JVMis minimized and does not require garbage collection (GC) activity tofree memory. The disadvantage (D1) of this approach is the GC continuesto manage the memory consumed by the balloon objects in the heap asnormal objects, which accordingly adds overhead. In another example,when the GC moves objects (for example, during a compact operation) theGC may move the objects, also including the balloon object thus forcingthe objects back into memory. The balloon object could detect thisoccurrence and free the memory but with additional overhead expended andmemory pressure increased while the objects are moved (D2).

In another example in which a dynamically modified target for a heap isused an advantage is obtained in minimizing objects that must be handledby the GC. Minimizing objects that must be handled enables the GC tomanage the objects optimally based on actual objects used by theapplication and a target available memory rather than being misled byspecial balloon objects. However a disadvantage (D3) of this example isthe objects typically require relocation before memory can be freed andaccordingly returned to the operating system. The GC activity requiredto move the objects therefore typically has an associated premium in theform of computation and paging overhead.

SUMMARY

According to an embodiment, a computer-implemented method for workingset adjustment receives a request to use less heap memory than anoriginal maximum forming a new maximum, determines whether a garbagecollection will move objects in response to the request. Responsive to adetermination the garbage collection will move objects, add a firstcallback triggered by initiation of the garbage collection and invokinga handler for the first callback notifying a memory manager to freeobjects allocated by balloon. The first callback completes and thegarbage collection starts. A handler for a second callback is invokedwhich notifies the memory manager to allocate balloon objects and freesbacking memory to an operating system. Completion of the second callback allows the garbage collection to proceed as usual.

According to another embodiment, a computer program product for workingset adjustment comprises a computer readable storage device containingcomputer executable program code stored thereon. The computer executableprogram code comprises computer executable program code for receiving arequest to use less heap memory than an original maximum forming a newmaximum; computer executable program code for determining whether agarbage collection will move objects in response to the request;computer executable program code responsive to a determination thegarbage collection will move objects, adding a first callback triggeredby initiation of the garbage collection that will move objects; computerexecutable program code for invoking a handler for the first callbacknotifying a memory manager to free objects allocated by balloon;computer executable program code for completing the first callback andstarting the garbage collection; computer executable program code forinvoking a handler for a second callback which notifies the memorymanager to allocate balloon objects and frees backing memory to anoperating system; computer executable program code for completing thesecond call back allowing the garbage collection to proceed as usual.

According to another embodiment, an apparatus for working set adjustmentcomprises a communications fabric; a memory connected to thecommunications fabric, wherein the memory contains computer executableprogram code; a communications unit connected to the communicationsfabric; an input/output unit connected to the communications fabric; adisplay connected to the communications fabric; and a processor unitconnected to the communications fabric. The processor unit executes thecomputer executable program code to direct the apparatus to receive arequest to use less heap memory than an original maximum forming a newmaximum; determine whether a garbage collection will move objects inresponse to the request; responsive to a determination the garbagecollection will move objects, add a first callback triggered byinitiation of the garbage collection that will move objects; invoke ahandler for the first callback notifying a memory manager to freeobjects allocated by balloon; complete the first callback and startingthe garbage collection; invoke a handler for a second callback whichnotifies the memory manager to allocate balloon objects and freesbacking memory to an operating system; and complete the second call backallowing the garbage collection to proceed as usual.

BRIEF DESCRIPTION OF THE SEVERAL VIEWS OF THE DRAWINGS

For a more complete understanding of this disclosure, reference is nowmade to the following brief description, taken in conjunction with theaccompanying drawings and detailed description, wherein like referencenumerals represent like parts.

FIG. 1 is a block diagram of an exemplary network data processing systemoperable including a working set adjustment system for variousembodiments of the disclosure;

FIG. 2 is a block diagram of an exemplary data processing systemincluding a working set adjustment system operable for variousembodiments of the disclosure;

FIG. 3 is a block diagram representation of a working set adjustmentsystem operable for various embodiments of the disclosure;

FIG. 4 is a block diagram of data structures in a garbage collectionusing the system of FIG. 3 in accordance with an embodiment of thedisclosure;

FIG. 5 is a block diagram of data structures in a garbage collectionwhich may move objects using the system of FIG. 3 in accordance with anembodiment of the disclosure;

FIG. 6 is a block diagram of data structures in a garbage collectionwhich does not move objects to free memory using the system of FIG. 3 inaccordance with an embodiment of the disclosure;

FIG. 7 is a block diagram of garbage collection process which may moveobjects to free memory using a callback of the system of FIG. 3 inaccordance with an embodiment of the disclosure;

FIG. 8 is a block diagram of a data structures after a garbagecollection garbage collection which moves objects to free memory inaccordance with an embodiment of the disclosure;

FIG. 9 is a block diagram of data structures in a garbage collectionwhich does not move objects to free memory using a working setadjustment system of FIG. 3 in accordance with an embodiment of thedisclosure; and

FIG. 10 is a flowchart of a process using garbage collection, using aworking set adjustment system of FIG. 3 in accordance with an embodimentof the disclosure.

DETAILED DESCRIPTION

Although an illustrative implementation of one or more embodiments isprovided below, the disclosed systems and/or methods may be implementedusing any number of techniques. This disclosure should in no way belimited to the illustrative implementations, drawings, and techniquesillustrated below, including the exemplary designs and implementationsillustrated and described herein, but may be modified within the scopeof the appended claims along with their full scope of equivalents.

As will be appreciated by one skilled in the art, aspects of the presentdisclosure may be embodied as a system, method or computer programproduct. Accordingly, aspects of the present disclosure may take theform of an entirely hardware embodiment, an entirely software embodiment(including firmware, resident software, micro-code, etc.) or anembodiment combining software and hardware aspects that may allgenerally be referred to herein as a “circuit,” “module,” or “system.”Furthermore, aspects of the present invention may take the form of acomputer program product embodied in one or more computer readablemedium(s) having computer readable program code embodied thereon.

Any combination of one or more computer-readable data storage devicesmay be utilized. A computer-readable data storage device may be, forexample, but not limited to, an electronic, magnetic, optical, orsemiconductor system, apparatus, or device, or any suitable combinationof the foregoing, but does not encompass propagation media. Morespecific examples (a non-exhaustive list) of the computer-readable datastorage devices would include the following: a portable computerdiskette, a hard disk, a random access memory (RAM), a read-only memory(ROM), an erasable programmable read-only memory (EPROM or Flashmemory), a portable compact disc read-only memory (CDROM), an opticalstorage device, or a magnetic storage device or any suitable combinationof the foregoing, but does not encompass propagation media. In thecontext of this document, a computer-readable data storage device may beany tangible device that can store a program for use by or in connectionwith an instruction execution system, apparatus, or device.

Computer program code for carrying out operations for aspects of thepresent disclosure may be written in any combination of one or moreprogramming languages, including an object oriented programming languagesuch as Java, Smalltalk, C++, or the like and conventional proceduralprogramming languages, such as the “C” programming language or similarprogramming languages. The program code may execute entirely on theuser's computer, partly on the user's computer, as a stand-alonesoftware package, partly on the user's computer and partly on a remotecomputer or entirely on the remote computer or server. In the latterscenario, the remote computer may be connected to the user's computerthrough any type of network, including a local area network (LAN) or awide area network (WAN), or the connection may be made to an externalcomputer (for example, through the Internet using an Internet ServiceProvider).

Aspects of the present disclosure are described below with reference toflowchart illustrations and/or block diagrams of methods, apparatus,(systems), and computer program products according to embodiments of theinvention. It will be understood that each block of the flowchartillustrations and/or block diagrams, and combinations of blocks in theflowchart illustrations and/or block diagrams, can be implemented bycomputer program instructions.

These computer program instructions may be provided to a processor inone or more processors of a general purpose computer, special purposecomputer, or other programmable data processing apparatus to produce amachine, such that the instructions, which execute via the processor ofthe one or more processors of the computer or other programmable dataprocessing apparatus, create means for implementing the functions/actsspecified in the flowchart and/or block diagram block or blocks.

These computer program instructions may also be stored in a computerreadable storage device that can direct a computer or other programmabledata processing apparatus to function in a particular manner, such thatthe instructions stored in the computer readable storage device producean article of manufacture including instructions which implement thefunction/act, when executed by the processor of the one or moreprocessors of the computer specified in the flowchart and/or blockdiagram block or blocks.

The computer program instructions may also be loaded onto a computer orother programmable data processing apparatus to cause a series ofoperational steps to be performed on the computer or other programmableapparatus to produce a computer-implemented process such that theinstructions which execute on the processor of the one or moreprocessors of the computer or other programmable apparatus provideprocesses for implementing the functions/acts specified in the flowchartand/or block diagram block or blocks.

With reference now to the figures and in particular with reference toFIGS. 1-2, exemplary diagrams of data processing environments areprovided in which illustrative embodiments may be implemented. It shouldbe appreciated that FIGS. 1-2 are only exemplary and are not intended toassert or imply any limitation with regard to the environments in whichdifferent embodiments may be implemented. Many modifications to thedepicted environments may be made.

FIG. 1 depicts a pictorial representation of a network of dataprocessing systems in which illustrative embodiments may be implemented.Network data processing system 100 is a network of computers in whichthe illustrative embodiments may be implemented. Network data processingsystem 100 contains network 102, which is the medium used to providecommunications links between various devices and computers connectedtogether within network data processing system 100. Network 102 mayinclude connections, such as wire, wireless communication links, orfiber optic cables.

In the depicted example, server 104 and server 106 connect to network102 along with storage unit 108. In addition, clients 110, 112, and 114connect to network 102. Clients 110, 112, and 114 may be, for example,personal computers or network computers. In the depicted example, server104 provides data, such as boot files, operating system images, andapplications to clients 110, 112, and 114. Clients 110, 112, and 114 areclients to server 104 in this example. Network data processing system100 may include additional servers, clients, and other devices notshown.

In the depicted example, network data processing system 100 is theInternet with network 102 representing a worldwide collection ofnetworks and gateways that use the Transmission ControlProtocol/Internet Protocol (TCP/IP) suite of protocols to communicatewith one another. At the heart of the Internet is a backbone ofhigh-speed data communication lines between major nodes or hostcomputers, consisting of thousands of commercial, governmental,educational and other computer systems that route data and messages.Network data processing system 100 also may be implemented as a numberof different types of networks, such as for example, an intranet, alocal area network (LAN), or a wide area network (WAN). FIG. 1 isintended as an example, and not as an architectural limitation for thedifferent illustrative embodiments.

With reference to FIG. 2 a block diagram of an exemplary data processingsystem operable for various embodiments of the disclosure is presented.In this illustrative example, data processing system 200 includescommunications fabric 202, which provides communications betweenprocessor unit 204, memory 206, persistent storage 208, communicationsunit 210, input/output (I/O) unit 212, and display 214.

Processor unit 204 serves to execute instructions for software that maybe loaded into memory 206. Processor unit 204 may be a set of one ormore processors or may be a multi-processor core, depending on theparticular implementation. Further, processor unit 204 may beimplemented using one or more heterogeneous processor systems in which amain processor is present with secondary processors on a single chip. Asanother illustrative example, processor unit 204 may be a symmetricmulti-processor system containing multiple processors of the same type.

Memory 206 and persistent storage 208 are examples of storage devices216. A storage device is any piece of hardware that is capable ofstoring information, such as, for example without limitation, data,program code in functional form, and/or other suitable informationeither on a temporary basis and/or a permanent basis. Memory 206, inthese examples, may be, for example, a random access memory or any othersuitable volatile or non-volatile storage device. Persistent storage 208may take various forms depending on the particular implementation. Forexample, persistent storage 208 may contain one or more components ordevices. For example, persistent storage 208 may be a hard drive, aflash memory, a rewritable optical disk, a rewritable magnetic tape, orsome combination of the above. The media used by persistent storage 208also may be removable. For example, a removable hard drive may be usedfor persistent storage 208.

Communications unit 210, in these examples, provides for communicationswith other data processing systems or devices. In these examples,communications unit 210 is a network interface card. Communications unit210 may provide communications through the use of either or bothphysical and wireless communications links.

Input/output unit 212 allows for input and output of data with otherdevices that may be connected to data processing system 200. Forexample, input/output unit 212 may provide a connection for user inputthrough a keyboard, a mouse, and/or some other suitable input device.Further, input/output unit 212 may send output to a printer. Display 214provides a mechanism to display information to a user.

Instructions for the operating system, applications and/or programs maybe located in storage devices 216, which are in communication withprocessor unit 204 through communications fabric 202. In theseillustrative examples the instructions are in a functional form onpersistent storage 208. These instructions may be loaded into memory 206for execution by processor unit 204. The processes of the differentembodiments may be performed by processor unit 204 usingcomputer-implemented instructions, which may be located in a memory,such as memory 206.

These instructions are referred to as program code, computer usableprogram code, or computer readable program code that may be read andexecuted by a processor in processor unit 204. The program code in thedifferent embodiments may be embodied on different physical or tangiblecomputer readable storage media, such as memory 206 or persistentstorage 208.

Program code 218 is located in a functional form on computer readablestorage media 220 that is selectively removable and may be loaded ontoor transferred to data processing system 200 for execution by processorunit 204. Program code 218 and computer readable media 220 form computerprogram product 222 in these examples. In one example, computer readablemedia 220 may be in a tangible form, such as, for example, an optical ormagnetic disc that is inserted or placed into a drive or other devicethat is part of persistent storage 208 for transfer onto a storagedevice, such as a hard drive that is part of persistent storage 208. Ina tangible form, computer readable storage media 220 also may take theform of a persistent storage, such as a hard drive, a thumb drive, or aflash memory that is connected to data processing system 200. Thetangible form of computer readable storage media 220 is also referred toas computer recordable storage media or a computer readable storagedevice 224. In some instances, computer readable media 220 may not beremovable.

Alternatively, program code 218 may be transferred to data processingsystem 200 from computer readable media 220 through a communicationslink to communications unit 210 and/or through a connection toinput/output unit 212 using computer readable signal media 226. Thecommunications link and/or the connection may be physical or wireless inthe illustrative examples.

In some illustrative embodiments, program code 218 may be downloadedover a network to persistent storage 208 from another device or dataprocessing system for use within data processing system 200. Forinstance, program code stored in a computer readable data storage devicein a server data processing system may be downloaded over a network fromthe server to data processing system 200. The data processing systemproviding program code 218 may be a server computer, a client computer,or some other device capable of storing and transmitting program code218.

Using data processing system 200 of FIG. 2 as an example, acomputer-implemented process for working set adjustment is presented.Processor unit 204 receives a request to use less heap memory than anoriginal maximum forming a new maximum, determines whether a garbagecollection will move objects in response to the request. Responsive to adetermination the garbage collection will move objects, processor 204adds a first callback triggered by initiation of the garbage collectionand invokes a handler for the first callback notifying a memory managerto free objects allocated by balloon. The first callback completes andthe garbage collection starts.

A handler for a second callback is invoked by processor 204 notifyingthe memory manager to allocate balloon objects and frees backing memoryto an operating system. Completion of the second call back allows thegarbage collection, using processor 204, to proceed as usual.

One illustrative embodiment comprises a computer-implemented method foradjustment of a working set of a virtual machine. Thecomputer-implemented process of the illustrative embodiment receives arequest by the virtual machine to reduce memory usage to a new targetlevel of memory usage and further determines whether to free memorywithout invoking a garbage collection.

Responsive to a determination to free memory without invoking a garbagecollection, a garbage collector frees any memory in a heap, withouthaving to start a garbage collection, up to an amount necessary to meetthe new target level of memory usage; sets a new dynamic target for amaximum heap size to a value of the new target level of memory usagerequested; allocates one or more dummy objects in the heap in an amountrequired to reduce a non-balloon memory used by the heap to the newtarget level of memory usage requested and returns memory for the dummyobjects to an operating system.

Responsive to a determination to free memory by invoking a garbagecollection, wherein the garbage collection causes objects to be moved,the garbage collector signals logic responsible for handling memorypressure to perform the steps of: indicating a type of garbagecollection that will occur; selectively free balloon objects which canbe moved; complete collection activity, upon which the garbage collectorsignals the logic responsible for handling memory pressure to create newballoon objects to enable a return of memory to the operating system.

Responsive to a determination to free memory by invoking a garbagecollection, wherein the garbage collection will not cause objects to bemoved, the garbage collector signals logic responsible for handlingmemory pressure to perform the steps of release the memory to theoperating system by the garbage collector; signal the logic responsiblefor handling memory pressure with the amount of memory released by thegarbage collector; and free the balloon objects in the amount of thememory already released to the operating system.

With reference to FIG. 3 a block diagram representation of a working setadjustment system operable for various embodiments of the disclosure ispresented. Working set adjustment system 300 is an example of anembodiment of the disclosed method. In the example used, a set comprisesone or more elements. The components described are not limited to animplementation of the illustrative embodiment but may be arranged inother combinations as necessary for a specific implementation withoutloss of functionality. For example the components as illustrated inworking set system 300 of FIG. 3 may be implemented as a monolithicstructure defined as enhanced JVM 302.

Enhanced JVM 302 includes a capability to receive an indication the JVMshould attempt to use less memory. The usage reduction may be based onoperating system memory pressure, information from a hypervisor or anyother mechanism. The information or notification is not part of theinstant disclosure but is a pre-requisite to use of the disclosedmethod. Enhanced JVM 302 further provides a capability to dynamicallyset a new target maximum heap size.

Enhanced JVM 302 is comprised of a number of components includingenhanced garbage collector 304, callback handler 306, memory manager308, balloon creator 310 and balloon objects 312.

Enhanced garbage collector 304 provides a capability to respond tosignals from callback handler 306 or memory manager 308. Responsive tothe signals comprising information on a current status of the memory ofa heap being managed, enhanced garbage collector 304 can dynamicallyadjust behavior to return memory to an operating system and avoid ascheduled garbage collection.

Callback handler 306 provides a mechanism in which a callback can beissued and received enabling status of the memory of a managed heap tobe communicated to enhanced garbage collector 304.

Memory manager 308 provides logic responsible for handling memorypressure caused by application allocation and de-allocation of heapmemory.

Balloon creator 310 provides a capability to create or allocate one ormore dummy objects in the heap being managed in an amount required toreduce a non-balloon memory used by the heap. Balloon objects 312 arethe dummy objects created by balloon creator 310 used to better manageheap memory allocation. Balloon objects 312 occupy space but disappeardynamically and are never moved. Balloon objects 312 represent a spacemaintaining technique.

When enhanced JVM 302 is requested to use less memory, in one instance,enhanced garbage collector 304 frees any memory in the heap withouthaving to start a garbage collection up to an amount necessary to meet anew target. For example when there is free contiguous memory at the endof the heap, or regions known to be empty. In another instance enhancedJVM 302 sets a new dynamic target for a maximum heap size to a valuerequested. In another instance enhanced JVM 302 allocates dummy objects(balloon objects 312) using balloon creator 310 in the heap in an amountrequired to reduce non-balloon memory used by the heap to the levelrequested, and returns the memory for these objects back to theoperating system. For example using a function of madvise(MADV_DONTNEED) when available on a platform of data processing system200.

When the creation of the dummy objects triggers a garbage collectionsuch that objects will be moved, the creation of balloon objects 312 isaborted because using the new target set the enhanced logic of theworking set adjustment system assumes control. Optionally the disclosedmethod includes directing balloon creator 310 to allocate balloonobjects 312 in a particular manner. For example when using agenerational collector selection of an allocation by balloon creator 310to allocate balloon objects 312 in one of new space or old space isenabled.

This results in free regions of the heap consumed by dummy objects whosebacking memory has been returned to the operating system and therebyavoiding problem D3. Note that when “balloon” objects are created theyare established for efficient scanning required in later stages of thedisclosed technique.

The enhanced logic is used when an allocation in the applicationsubsequently causes a garbage collection and the particular garbagecollection causes objects to be moved. The enhanced logic includesreceiving signals from enhanced garbage collector 304 by logicresponsible for handling memory pressure of memory manager 308indicating what type of garbage collection will occur.

Balloon objects 312 which could be moved are selectively freed. Forexample, when in a generational collector the collection that will takeplace is only in new space, only those objects that were allocated fromnew space will be freed). The collection by enhanced garbage collector304 is allowed to complete. Enhanced garbage collector 304 signals thelogic responsible for handling memory pressure of memory manager 308.When necessary, new balloon objects 312 are created to return memoryback to the operating system. This may be necessary because althoughobjects in a particular space are freed the dynamic target may notaffect the particular space in the same ratio as the balloon objectsthat were allocated the particular space.

By removing the balloon objects at the garbage collection point thedisclosed method typically avoids overhead cited as D1 previouslybecause balloon objects disappear dynamically and D2 previously becauseballoon objects are never moved.

When objects are freed or an allocation by the applications causes agarbage collection that will not move objects the enhanced garbagecollector 304 can release memory back to the operating system, signalthe logic of memory manager 308 responsible for handling memory pressurewith the amount of memory released and free balloon objects 312 in theamount of the memory already released back to the operating system.

An alternative of using either previous solution of the balloontechnique or the dynamically adjusted maximum heap has disadvantages.When using the previous balloon technique the garbage collectioncontinues to manage memory consumed by the balloon objects in the heap,which incurs additional overhead, and the garbage collection may moveobjects allocated from the balloon thus forcing the objects back intomemory. This movement can result in spikes in memory pressure as well asadditional overhead in the garbage collection.

When using the previous dynamic maximum heap target, once the target isset, additional garbage collection activity (for example compacting) istypically necessary to have the heap in a condition in which memory canbe freed. This activity introduces additional overhead and might alsolimit how fast memory can be returned to the operating system.

In contrast when using an embodiment of the working set adjustmentsystem 300 of the disclosure the memory is returned immediately to theoperating system without requiring any garbage collection activity.Because as normal garbage collection activity occurs driven byapplication memory usage, an embodiment of the working set adjustmentsystem 300 avoids copying balloon allocated objects and moves towards atarget state with no balloon objects where the target is managed by thegarbage collection without having to introduce any artificial garbagecollection activity. The result is the embodiment of the working setadjustment system 300 quickly addresses memory pressure while at thesame time minimizing required additional CPU overhead achieving a bettermemory/CPU trade off than typically achieve with previously availabletechniques.

With reference to FIG. 4 a block diagram of data structures in a garbagecollection using the system of FIG. 3 in accordance with an embodimentof the disclosure is presented. Example 400 presents a view in which afirst part of the disclosed method using less heap memory than anoriginal maximum using is presented. Example 400 depicts handling aninitial request to use less heap memory than the original maximum.

In the example, Java heap 402 is in an initial state with hard max 410and soft max 412. Java heap 402 further contains objects-1 406 andobjects-2 408 allocated within. Hard max 410 and a soft max 412 as setin the initial state are at the same setting or value. A technique ofthe disclosed method now sets a new dynamic maximum heap size. Java heap404 is in an adjusted state with hard max 410 as before but with softmax 412 at a new or adjusted setting. Java heap 402 further containsobjects-1 406 and objects-2 408 allocated within as before.

In some cases the garbage collections may be enabled to easily satisfy arequest for space without rearranging the heap as depicted. Notice softmax line 416 is lowered from an first setting of soft max 412 in theinitial state of Java heap 402 (same as hard max 410) to a new settingof soft max 412 in Java heap 404 without moving either objects ofobjects-1 406 and objects-2 408.

Memory between objects-1 406 and hard max 410 (and soft max 412) musthave been used at some point in a run. Otherwise this memory would havebeen reserved, but not committed. In example 400 region 414, betweenhard max 410 and soft max 412, of Java heap 404 is simply returned tothe operating system as unused and therefore freed memory.

With reference to FIG. 5 a block diagram of data structures in a garbagecollection, which may move objects using the system of FIG. 3 inaccordance with an embodiment of the disclosure is presented. Example500 depicts processing of an initial request to use less heap memorythan an original maximum.

In the example, Java heap 402 is in an initial state with hard max 410and soft max 412. Java heap 402 further contains objects-1 406 andobjects-2 408 allocated within. Hard max 410 and a soft max 412 as setin the initial state are at the same setting or value. A technique ofthe disclosed method now sets a new dynamic maximum heap size. Java heap402 also contains objects-1 406 and objects-2 408 allocated within asbefore. Java heap 404 is in an adjusted state representation of Javaheap 402, with hard max 410 as before but with soft max 412 at a new oradjusted setting, which accordingly requires movement of objects-1 406to free needed memory.

In example 500 the garbage collection cannot easily satisfy a requestfor memory without rearranging the heap from an initial state to anadjusted state as depicted. Notice soft max line 416 is lowered fromsoft max 412 in the initial state of Java heap 402 (same level as hardmax 410) to a new setting of soft max 412 in Java heap 404. The loweringof soft max 412 from the initial state setting accordingly requires amovement of one or more objects of objects-1 406 and objects-2 408.Objects-2 408 as in Java heap 404 of the example cannot be readilymoved; therefore objects-1 406 is an identified move candidate.

In example 500, region 502, between hard max 410 and soft max 412, ofJava heap 404 is now returned to the operating system. As shown in theexample, it is equally likely that objects will need to be rearranged tolower the setting of soft max 412. As depicted in the example, soft maxline 416 cannot be lowered without first moving objects-1 406 at a costof additional processor cycles and memory bandwidth. Gaps betweenobjects, as between objects-1 406 and objects-2 408 of Java heap 402 areexpected and a natural side effect of object allocation and freeoperations through a run. The size and location of these gaps however isnot predictable.

With reference to FIG. 6 a block diagram of data structures in a garbagecollection, which does not move objects to free memory using the systemof FIG. 3 in accordance with an embodiment of the disclosure ispresented. Example 600 is an example of using a balloon object to avoidmoving objects in accordance with the disclosed method.

Example 600 depicts handling an initial request to use less heap memorythan the original maximum. In the example Java heap 402 is in an initialstate with hard max 410 and soft max 412 set at the same level. Javaheap 402 further contains objects-1 406 and objects-2 408 allocatedwithin. Hard max 410 and a soft max 412 as set in the initial state areat the same setting or value. A technique of the disclosed method nowsets a new dynamic maximum heap size. Java heap 404 is in an adjustedstate with hard max 410 as before but with soft max 412 at a new oradjusted setting, which may require movement of objects-1 406 to freeneeded memory.

In example 600 the garbage collections cannot easily satisfy a requestfor memory without rearranging the heap. Notice soft max line 416 islowered from a previous setting of soft max 412 (same as initial settingof hard max 410) in the initial state of Java heap 402 to a new settingof soft max 412 in Java heap 404. The lowering of soft max 412 from theinitial state setting appears to require a movement of either objects ofobjects-1 406 and objects-2 408. Objects-2 408, as in Java heap 404 ofthe example, cannot be readily moved; therefore objects-1 406 isidentified as a move candidate.

In example 600, region 602, between hard max 410 and soft max 412, ofJava heap 404 is now returned to the operating system. As shown in theexample, it is equally likely that objects will need to be rearranged tolower the setting of soft max 412. As depicted in the example, soft maxline 416 cannot be lowered without first moving objects-1 406 at a costof additional processor cycles and memory bandwidth. Gaps betweenobjects, as between objects-1 406 and objects-2 408 of Java heap 402 areexpected and a natural side effect of object allocation and object freeoperations through normal processing cycles. The size and location ofthese gaps however is not predictable.

Rather than initiating a garbage collection activity requiringreclaiming and returning memory an embodiment of the disclosed methodallocates balloon object 604 to consume an amount of space equal to aremaining portion of memory necessary to return to the operating system.For example, a technique of madvise(MADV_DONTNEED) used on a platformcomprising Linux® or disclaim( ) on an system using AIX® might be usedas an aid to return most of the memory for the balloon objects back tothe respective operating system. The resulting heap shape, afterreduction of the balloon objects, has the same amount of free space inthe heap.

A contiguous area 602 at the top of Java heap 404 and the contents ofin-heap balloon 604 have been returned to the operating system withoutneeding to rearrange the heap. The combination of allocated space ofcontiguous area 602 and in-heap balloon 604 is equal to a desired amountof returned space. A size of in-heap balloon 604 is accordinglyallocated equal to a size of (soft max 412−contiguous area 602).

At this point in the process an embodiment of the disclosed method hasreturned approximately the same amount of memory to the operating systemas a conventional garbage collection but has not incurred the resourceoverhead needed to move objects. In actual use the heap shape may bemuch more complicated, with allocated ranges and free ranges beinginterleaved. Use of the disclosed technique would achieve the sameresult.

As in the example, when there is not enough free memory in the heap toaccommodate the new target max, garbage collection may be triggered toallocate the balloon objects. Because a new target maximum is set, whengarbage collection activity results in memory being returned to anoperating system, the garbage collection will allocate the balloonobjects and a size of the balloon objects created is based on thecurrent size of the memory used by the heap. The balloon object sizeallocation would therefore be determined by checking a size of physicalmemory used for a heap. Balloon allocation size is determined, in anumber of iterations, using a calculation expressed as (size of physicalmemory for heap−total balloon size) relative to a value of new max. Foreach next balloon object allocated a size of physical memory used forthe heap is checked again. When the expression (size of physical memoryfor heap−total balloon size) is equal to or less than new max, theoperation stops.

In each loop of the iteration the total balloon size is incremented,causing a value of (size of physical memory for heap−total balloon size)to be reduced. A determination is also made in each of the iterations asto whether the value represented by (size of physical memory forheap−total balloon size) becomes smaller than the value set for new max.

Given a new target is set, the space available for use in the heap is(size of physical memory for heap−total balloon size). When thecalculated value is greater than the target new max then another balloonobject needs to be allocated to reduce the available value towards thetarget value. When the calculation of (size of physical memory forheap−total balloon size) is equal to or less than the target value ofnew max the allocation operations stop. However when the allocationoperations exhaust free memory the allocation operations also stop.

It is expected that either the required balloon size is successfullyallocated or more aggressive steps are needed to get to the new targetsize including a transition to handling of garbage collections, whichmay move objects. Once the balloon inflation is successful theapplication continues to run as before and objects can further beallocated and freed within the area occupied by objects-1 406 andobjects-2 408 and the free area (unmarked area indicating unallocatedheap storage). Using the disclosed balloon inflation adjustment,inflation and deflation (or elimination) of the balloon is used toabsorb and release heap memory rather than moving of objects in theheap.

With reference to FIG. 7 a block diagram of data structures in a garbagecollection using a callback of the system of FIG. 3 in accordance withan embodiment of the disclosure is presented. Process 700 is an exampleof a set of operations over a period of time representative of an objectmoving garbage collection in an embodiment of the disclosed method.

(1) When garbage collector 718 is triggered which might move objects 702and 704 in process 700 to increase free space 708 to achieve new max706, the moving or copying balloon objects 716 is to be avoided whenpossible. Avoidance is because moving or copying balloon objects 716 isa needless consumption of processor cycles and memory bandwidth. Garbagecollector 718 triggers a first callback and invokes a callback handler720 when a garbage collection that might cause objects to move istriggered in process 700. The callback optionally includes a type ofgarbage collection. Garbage collector 718 waits until the first callbackis completed before proceeding with the garbage collection to avoidunnecessary object movement.

(2) Callback handler 720 processes the first callback notifying a memorymanager to free objects allocated by the balloon objects when the firstcallback was triggered during process 700 to provide an increase inallocation of free space 708 to free space 710.

(3) Process 700 invokes the callback handler for a second callbacktriggered by garbage collector 718 when a garbage collection cycle thatmight move objects is completed resulting in a portion of free spacebeing returned to an operating system and leaving free space 712.

(4) Callback handler 720 processes the second callback notifying thememory manager to create balloon objects, such as balloon objects 716,required when the second callback is received. Free space is now furtherreduced due to creation of balloon objects 716, and is now shown as freespace 714.

In an alternate view of the just described process 700, consider thetimeline 722 in which at t1 application allocations cause garbagecollector 718 to trigger a garbage collection that might move objects.At t2 garbage collector 718 invokes callback handler 720 to inform thelogic managing memory pressure of object moving garbage collect 724.

At t3 the logic managing memory pressure frees balloon objects. At t4the logic managing memory pressure completes the callback processingwith callback handler 720 and garbage collector 718 continues 726 thegarbage collection.

At t5 objects have been moved and the garbage collection is complete.However garbage collector 718 may not have achieved the new maximumspecified. At t6 garbage collector 718 invokes callback handler 720again to inform the logic managing memory pressure that garbagecollection is complete 728.

At t7 the logic managing memory pressure, allocates balloon objects andfrees the memory backing the balloon objects to the operating systemsuch that physical memory for heap−total balloon size=new max. At t8 thelogic managing memory pressure, returns from callback handler 720 andgarbage collector 718 continues 730 as usual.

With reference to FIG. 8 a block diagram of data structure after agarbage collection, which moves objects to free memory in accordancewith an embodiment of the disclosure, is presented. Data structure 800is an example of an in memory representation of heap allocations.

In an ideal case when garbage collector 718 of FIG. 7 moves objects theobjects are moved such that a memory data structure is directlyallocated in a desired shape rather than in the form of data structure800. In data structure 800 objects-1 702 and objects-2 704 have beenmoved together with no free space or balloon space separating the twoobjects. New max 706 is at a rightmost end of data structure 800 andfree space 802 lies between objects-2 704 and new max 706.

With reference to FIG. 9 is a block diagram of data structures in agarbage collection which does not move objects to free memory using aworking set adjustment system of FIG. 3 in accordance with an embodimentof the disclosure.

In the example, application activity may trigger garbage collections,which do not need to move objects, or the activity may simply freememory enabling the garbage collection to easily free memory back to theoperating system. For example in a region based collector a region maybecome completely free. In this example process 900 adds a callbacktriggered by a return of memory back to the operating system by garbagecollection 918 which includes the amount of memory freed and a handlerfor the callback notifying a memory manager which frees objectsallocated by the balloon in an amount corresponding to the memory freedby the garbage collection.

The example uses a data structure representing allocations within heapmemory comprising objects1 902, objects2 904, free space 910, 914 orballoon objects 908, 912 and new max 926. The data structure changesduring processing are shown in relation to timeline 920 described in thefollowing sections.

Using the timeline 920 containing times of t1 through t6, at t1 theballoon/heap size/dynamic target is in balance. At t2 either theapplication frees objects or garbage collection activity occurs suchthat the garbage collection can easily return memory to the operatingsystem.

At t3 the garbage collection returns memory to the operating system(922). At t4 the garbage collection triggers the callback to inform thelogic managing memory pressure.

At t5 the logic managing memory pressure frees balloon objects such thatphysical memory for heap−total balloon size=new max. At t6 the callbackcompletes and the garbage collection proceeds as it would otherwise(924). Note that the objects1 902, objects2 904, free space 910, 914 orballoon objects 908, 912 are likely to be contiguous, but they aresimply drawn that way to simplify. Balloon objects 908, are reduced inallocation to form balloon objects shown as balloon objects 912. In asimilar manner free space 914 is reduced and shown as free space 916.New max 926 is maintained.

The disclosed method typically achieves a goal of using only an amountof physical memory set by a dynamic maximum while minimizing anyadditional processor or memory bandwidth resources required.

With reference to FIG. 10 a flowchart of a process using garbagecollection, using a working set adjustment system of FIG. 3 inaccordance with an embodiment of the disclosure is presented. Process1000 is an example of a process using a garbage collection, using theworking set adjustment system 116 of FIG. 3.

Process 1000 begins (step 1002) and receives a request to use less heapmemory than an original maximum forming a new maximum (step 1004).Process 1000 determines whether a garbage collection will move objectsin response to the request (step 1006).

Responsive to a determination the garbage collection will not moveobjects, process 1000 selects an execution path in which the garbagecollection simply frees memory or will not move objects (step 1020).Process 1000 adds a third callback triggered by the garbage collectionreturn of memory to the operating system (step 1022). Process 1000invokes a handler for the third callback, which frees objects, allocatedby balloon in an amount equal to the memory returned by the garbagecollection (step 1024) and terminates thereafter (step 1026).

Responsive to a determination the garbage collection will move objects,process 1000 selects a execution path of garbage collection will moveobjects (step 1008). Process 1000 adds a first callback triggered byinitiation of the garbage collection that will move objects (step 1010).Process 1000 invokes a handler for the first callback, notifying amemory manager to free objects allocated by balloon upon (step 1012).The first callback competes and garbage collection starts (step 1014).

Process 1000 invokes a handler for a second callback triggered bycompletion of garbage collection that may move objects which notifiesthe memory manager to allocate balloon objects and frees backing memoryto the operating system (step 1016). The second callback completes andgarbage collection proceeds as usual (step 1018) and process 1000terminates thereafter (step 1026).

Alternative embodiments of the disclosed method might implement aversion of garbage collection on a platform using madvise (DONT_NEED) ordisclaim ( ) freeing memory for all regions of the heap not currentlycontaining objects when a new target is set below current usage.However, overhead of the alternative on a per object/allocation basiswould typically be too expensive to be practical. Rather than usingballoon objects, the disclosed method could also be implemented enablingthe garbage collection to mark regions of the heap as not for use, anduse madvise (DONT_NEED) on these regions to achieve a similar result.

Specific implementations as described in the disclosure with a divisionbetween the garbage collection and other logic to manage memory pressureis solely for descriptive purposes and the disclosed method is intendedto cover any split/arrangement of the steps/actions disclosed such thatregions of the heap are reserved to prevent use for object allocationwherein most of the memory for these regions is returned to theoperating system and as the committed memory for the heap shrinkstowards a new dynamic maximum, the reserved areas are adjusted in aequal amount.

As outlined earlier extensions include support for allowing balloonobjects to be created in a specific way (for example, in the old spaceof a generational collector) and only freeing balloon objects whichcould be moved (for example, when a new space collect is not freeingpreviously allocated balloon objects in the old space).

Thus as presented in an illustrative embodiment, a computer-implementedmethod for working set adjustment receives a request to use less heapmemory than an original maximum forming a new maximum, determineswhether a garbage collection will move objects in response to therequest. Responsive to a determination the garbage collection willsimply free memory or not move objects, adds a third callback triggeredby the garbage collection return of memory to the operating system. Ahandler is invoked for the third callback, which frees objects,allocated in balloon objects in an amount equal to the memory returnedby the garbage collection.

Responsive to a determination the garbage collection will move objects,adds a first callback triggered by initiation of the garbage collectionthat will move objects. A handler for the first callback is invokednotifying a memory manager to free objects allocated by balloon. Thefirst callback completes and garbage collection starts. A handler for asecond callback is invoked which notifies the memory manager to allocateballoon objects and frees backing memory to the operating system.

The flowchart and block diagrams in the figures illustrate thearchitecture, functionality, and operation of possible implementationsof systems, methods, and computer program products according to variousembodiments of the present invention. In this regard, each block in theflowchart or block diagrams may represent a module, segment, or portionof code, which comprises one or more executable instructions forimplementing a specified logical function. It should also be noted that,in some alternative implementations, the functions noted in the blockmight occur out of the order noted in the figures. For example, twoblocks shown in succession may, in fact, be executed substantiallyconcurrently, or the blocks may sometimes be executed in the reverseorder, depending upon the functionality involved. It will also be notedthat each block of the block diagrams and/or flowchart illustration, andcombinations of blocks in the block diagrams and/or flowchartillustration, can be implemented by special purpose hardware-basedsystems that perform the specified functions or acts, or combinations ofspecial purpose hardware and computer instructions.

The corresponding structures, materials, acts, and equivalents of allmeans or step plus function elements in the claims below are intended toinclude any structure, material, or act for performing the function incombination with other claimed elements as specifically claimed. Thedescription of the present invention has been presented for purposes ofillustration and description, but is not intended to be exhaustive orlimited to the invention in the form disclosed. Many modifications andvariations will be apparent to those of ordinary skill in the artwithout departing from the scope and spirit of the invention. Theembodiment was chosen and described in order to best explain theprinciples of the invention and the practical application, and to enableothers of ordinary skill in the art to understand the invention forvarious embodiments with various modifications as are suited to theparticular use contemplated.

The invention can take the form of an entirely hardware embodiment, anentirely software embodiment or an embodiment containing both hardwareand software elements. In a preferred embodiment, the invention isimplemented in software, which includes but is not limited to firmware,resident software, microcode, and other software media that may berecognized by one skilled in the art.

It is important to note that while the present invention has beendescribed in the context of a fully functioning data processing system,those of ordinary skill in the art will appreciate that the processes ofthe present invention are capable of being distributed in the form of acomputer readable data storage device having computer executableinstructions stored thereon in a variety of forms. Examples of computerreadable data storage devices include recordable-type media, such as afloppy disk, a hard disk drive, a RAM, CD-ROMs, DVD-ROMs. The computerexecutable instructions may take the form of coded formats that aredecoded for actual use in a particular data processing system.

A data processing system suitable for storing and/or executing computerexecutable instructions comprising program code will include one or moreprocessors coupled directly or indirectly to memory elements through asystem bus. The memory elements can include local memory employed duringactual execution of the program code, bulk storage, and cache memorieswhich provide temporary storage of at least some program code in orderto reduce the number of times code must be retrieved from bulk storageduring execution.

Input/output or I/O devices (including but not limited to keyboards,displays, pointing devices, etc.) can be coupled to the system eitherdirectly or through intervening I/O controllers.

Network adapters may also be coupled to the system to enable the dataprocessing system to become coupled to other data processing systems orremote printers or storage devices through intervening private or publicnetworks. Modems, cable modems, and Ethernet cards are just a few of thecurrently available types of network adapters.

What is claimed is:
 1. A computer-implemented method for working setadjustment, the computer-implemented method comprising: receiving arequest to use less heap memory than an original maximum, forming a newmaximum; determining whether a garbage collection will move objects inresponse to the request received; adding a first callback triggered byinitiation of the garbage collection that will move objects, responsiveto a determination that the garbage collection will move objects;invoking a handler for the first callback notifying a memory manager tofree objects allocated by balloon; completing the first callback andstarting the garbage collection; invoking a handler for a secondcallback which notifies the memory manager to allocate balloon objectsand frees backing memory to an operating system; and completing thesecond call back allowing the garbage collection to proceed as usual. 2.The computer-implemented method of claim 1, wherein determining whethera garbage collection will move objects in response to the requestreceived further comprises: adding a third callback triggered by thegarbage collection return of memory to the operating system, responsiveto a determination that the garbage collection will simply free memoryor not move objects; and invoking a handler for the third callback,which frees objects allocated by balloon objects in an amount equal tomemory returned by the garbage collection.
 3. The computer-implementedmethod of claim 1, wherein return of memory to the operating systemcomprises freeing memory backing the objects allocated by balloon sothat physical memory for the heap minus total balloon size is equal tothe new maximum.
 4. The computer-implemented method of claim 1, furthercomprising: allocating a balloon object by determining a size ofphysical memory of the heap; determining whether the size of physicalmemory of the heap minus a total balloon size is greater than a newmaximum; allocating a next balloon object, responsive to a determinationthat the size of physical memory of the heap minus a total balloon sizeis greater than a new maximum; and terminating cycle, responsive to adetermination that the size of physical memory of the heap minus a totalballoon size is not greater than a new maximum.
 5. Thecomputer-implemented method of claim 1, wherein memory is returned tothe operating system without rearranging the heap, responsive to adetermination that the garbage collection will not move objects.
 6. Thecomputer-implemented method of claim 1, wherein specified regions of theheap are marked as reserved to prevent use for object allocation,wherein the specified regions of the heap marked as reserved are managedsimilar to balloon objects.
 7. The computer-implemented method of claim1, further comprising: allocating balloon objects in a specifiedlocation including one of new space and old space.
 8. A computer programproduct for working set adjustment, the computer program productcomprising: a computer readable storage device containing computerexecutable program code stored thereon, the computer executable programcode comprising: computer executable program code for receiving arequest to use less heap memory than an original maximum forming a newmaximum; computer executable program code for determining whether agarbage collection will move objects in response to the request;computer executable program code for adding a first callback triggeredby initiation of the garbage collection that will move objects,responsive to a determination that the garbage collection will moveobjects; computer executable program code for invoking a handler for thefirst callback notifying a memory manager to free objects allocated byballoon; computer executable program code for completing the firstcallback and starting the garbage collection; computer executableprogram code for invoking a handler for a second callback, whichnotifies the memory manager to allocate balloon objects, and freesbacking memory to an operating system; and computer executable programcode for completing the second call back allowing the garbage collectionto proceed as usual.
 9. The computer program product of claim 8, whereincomputer executable program code for determining whether a garbagecollection will move objects in response to the request furthercomprises: computer executable program code for adding a third callbacktriggered by the garbage collection return of memory to the operatingsystem, responsive to a determination that the garbage collection willsimply free memory or not move objects; and computer executable programcode for invoking a handler for the third callback, which frees objectsallocated by balloon objects in an amount equal to memory returned bythe garbage collection.
 10. The computer program product of claim 8,wherein computer executable program code for returning memory to theoperating system comprises: computer executable program code for freeingmemory backing the objects allocated by balloon so that physical memoryfor the heap minus total balloon size is equal to the new maximum. 11.The computer program product of claim 8, further comprising: computerexecutable program code for allocating a balloon object by determining asize of physical memory of the heap; computer executable program codefor determining whether the size of physical memory of the heap minus atotal balloon size is greater than a new maximum; computer executableprogram code for allocating a next balloon object, responsive to adetermination the size of physical memory of the heap minus a totalballoon size is greater than a new maximum; and computer executableprogram code for terminating cycle, responsive to a determination thesize of physical memory of the heap minus a total balloon size is notgreater than a new maximum.
 12. The computer program product of claim 8,wherein computer executable program code for adding a first callbacktriggered by initiation of the garbage collection that will moveobjects, responsive to a determination that the garbage collection willnot move objects, further comprises: computer executable program codefor returning memory to the operating system without rearranging theheap.
 13. The computer program product of claim 8, further comprising:computer executable program code for specifying regions where the heapare marked as reserved to prevent use for object allocation, wherein thespecified regions of the heap marked as reserved are managed similar toballoon objects.
 14. The computer program product of claim 8, furthercomprising: computer executable program code for allocating balloonobjects in a specified location including one of new space and oldspace.
 15. An apparatus for working set adjustment, the apparatuscomprising: a communications fabric; a memory connected to thecommunications fabric, wherein the memory contains computer executableprogram code; a communications unit connected to the communicationsfabric; an input/output unit connected to the communications fabric; adisplay connected to the communications fabric; and a processor unitconnected to the communications fabric, wherein the processor unitexecutes the computer executable program code to direct the apparatusto: receive a request to use less heap memory than an original maximumforming a new maximum; determine whether a garbage collection will moveobjects in response to the request; add a first callback triggered byinitiation of the garbage collection that will move objects, responsiveto a determination the garbage collection will move objects; invoke ahandler for the first callback notifying a memory manager to freeobjects allocated by balloon; complete the first callback and startingthe garbage collection; invoke a handler for a second callback whichnotifies the memory manager to allocate balloon objects and freesbacking memory to an operating system; and complete the second call backallowing the garbage collection to proceed as usual.
 16. The apparatusof claim 15, wherein the processor unit executes the computer executableprogram code to determine whether a garbage collection will move objectsin response to the request further directs the apparatus to: add a thirdcallback triggered by the garbage collection return of memory to theoperating system, responsive to a determination the garbage collectionwill simply free memory or not move objects; and invoke a handler forthe third callback, which frees objects allocated by balloon objects inan amount equal to memory returned by the garbage collection.
 17. Theapparatus of claim 15, wherein the processor unit executes the computerexecutable program code to return memory to the operating system furtherdirects the apparatus to: free memory backing the objects allocated byballoon so that physical memory for the heap minus total balloon size isequal to the new maximum.
 18. The apparatus of claim 15, wherein theprocessor unit executes the computer executable program code to furtherdirect the apparatus to: allocate a balloon object by determining a sizeof physical memory of the heap; determine whether the size of physicalmemory of the heap minus a total balloon size is greater than a newmaximum; allocate a next balloon object, responsive to a determinationthe size of physical memory of the heap minus a total balloon size isgreater than a new maximum; terminate cycle, responsive to adetermination the size of physical memory of the heap minus a totalballoon size is not greater than a new maximum.
 19. The apparatus ofclaim 15, wherein the processor unit executes the computer executableprogram code to further direct the apparatus to: specify regions of theheap marked as reserved to prevent use for object allocation, whereinthe specified regions of the heap marked as reserved are managed similarto balloon objects.
 20. The apparatus of claim 15, wherein the processorunit executes the computer executable program code to further direct theapparatus to: allocate balloon objects in a specified location includingone of new space and old space.